#include "stdio.h"
#include "opencv2/opencv.hpp"
#include "Detection.h"
#include "locate_target.h"

//locate_target::locate_target(int width,int height)
//{
//	reco( width,height);
//}
locate_target::locate_target()
{

}
locate_target::~locate_target()
{

}
bool locate_target::backtarget(cv::Mat img, Rect* target)
{

	IplImage img2 = img;
	IplImage * ImgLocatemp = &img2;

	cv::Mat gray = cv::Mat(img.rows,img.cols,CV_8UC1);
	cv::cvtColor(img,gray,CV_RGB2GRAY);
	IplImage temp = gray;
	IplImage * ImgLocatempGray = &temp;


	//uchar *buf = (uchar*)malloc(2*ImgLocatemp->width*ImgLocatemp->height*sizeof(char));
	uchar* buf = new uchar[2*ImgLocatemp->width*ImgLocatemp->height*sizeof(char)];

	cvCvtColor(ImgLocatemp, ImgLocatempGray, CV_BGR2GRAY);
	memset(buf,0,2*ImgLocatemp->width*ImgLocatemp->height*sizeof(char));

	
	PlateDetect reco(ImgLocatempGray->widthStep,ImgLocatempGray->height);
	reco.Getimage((unsigned char*)ImgLocatempGray->imageData,ImgLocatempGray->widthStep,ImgLocatempGray->height);
	bool hascar = reco.Detection((uchar*)ImgLocatempGray->imageData,buf,target);
	//free(buf);
	

	delete[] buf;
	return hascar;


}